<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>js-数组与递归思想 | lafen | lafen&#39;s personal blog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="learning,note,js,Array,递归">
    <meta name="description" content="数组遍历1. for1234const arr = [1, 9, 99, 888, 9999]for(let i = 0; i &amp;lt; arr.length; i++) &amp;#123;    console.log(i)&amp;#125; 2. for ofIterator 统一的遍历方法（详见），可使用 break、continue 和 return 语句 123for(let v of arr) &amp;">
<meta name="keywords" content="learning,note,js,Array,递归">
<meta property="og:type" content="article">
<meta property="og:title" content="js-数组与递归思想">
<meta property="og:url" content="https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/index.html">
<meta property="og:site_name" content="lafen">
<meta property="og:description" content="数组遍历1. for1234const arr = [1, 9, 99, 888, 9999]for(let i = 0; i &amp;lt; arr.length; i++) &amp;#123;    console.log(i)&amp;#125; 2. for ofIterator 统一的遍历方法（详见），可使用 break、continue 和 return 语句 123for(let v of arr) &amp;">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-11-17T03:05:48.407Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js-数组与递归思想">
<meta name="twitter:description" content="数组遍历1. for1234const arr = [1, 9, 99, 888, 9999]for(let i = 0; i &amp;lt; arr.length; i++) &amp;#123;    console.log(i)&amp;#125; 2. for ofIterator 统一的遍历方法（详见），可使用 break、continue 和 return 语句 123for(let v of arr) &amp;">
    
        <link rel="alternate" type="application/atom+xml" title="lafen" href="/atom.xml">
    
    <link rel="shortcut icon" href="/img/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide">
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">lafen</h5>
          <a href="mailto:1031822863@qq.com" title="1031822863@qq.com" class="mail">1031822863@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/">
                <i class="icon icon-lg icon-home"></i>
                home
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives">
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags">
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories">
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/zhongxiaotian" target="_blank">
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://www.weibo.com/" target="_blank">
                <i class="icon icon-lg icon-weibo"></i>
                Weibo
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://gitee.com/lafen" target="_blank">
                <i class="icon icon-lg icon-link"></i>
                Gitee
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">js-数组与递归思想</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">js-数组与递归思想</h1>
        <h5 class="subtitle">
            
                <time datetime="2019-11-17T02:37:57.000Z" itemprop="datePublished" class="page-time">
  2019-11-17
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/">js</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/Array/">Array</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/Array/learning/">learning</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/Array/learning/note/">note</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/Array/learning/note/递归/">递归</a></li></ul></li></ul></li></ul></li></ul></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#数组遍历"><span class="post-toc-number">1.</span> <span class="post-toc-text">数组遍历</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#1-for"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">1. for</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#2-for-of"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">2. for of</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#3-forEach"><span class="post-toc-number">1.3.</span> <span class="post-toc-text">3. forEach</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#4-map"><span class="post-toc-number">1.4.</span> <span class="post-toc-text">4. map</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#5-reduce"><span class="post-toc-number">1.5.</span> <span class="post-toc-text">5. reduce</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#6-filter"><span class="post-toc-number">1.6.</span> <span class="post-toc-text">6. filter</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#7-some"><span class="post-toc-number">1.7.</span> <span class="post-toc-text">7. some</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#8-every"><span class="post-toc-number">1.8.</span> <span class="post-toc-text">8. every</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#9-find"><span class="post-toc-number">1.9.</span> <span class="post-toc-text">9. find</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#10-findIndex"><span class="post-toc-number">1.10.</span> <span class="post-toc-text">10. findIndex</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#11-keys，values，entries"><span class="post-toc-number">1.11.</span> <span class="post-toc-text">11.  keys，values，entries</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#this指向的场景"><span class="post-toc-number">2.</span> <span class="post-toc-text">this指向的场景</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#递归"><span class="post-toc-number">3.</span> <span class="post-toc-text">递归</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#概念"><span class="post-toc-number">3.1.</span> <span class="post-toc-text">概念</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#关键"><span class="post-toc-number">3.2.</span> <span class="post-toc-text">关键</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#例子"><span class="post-toc-number">3.3.</span> <span class="post-toc-text">例子</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#递归注意事项"><span class="post-toc-number">3.4.</span> <span class="post-toc-text">递归注意事项</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-6"><a class="post-toc-link" href="#优化"><span class="post-toc-number">3.4.1.</span> <span class="post-toc-text">优化</span></a></li></ol></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#感悟"><span class="post-toc-number">3.5.</span> <span class="post-toc-text">感悟</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#递归场景"><span class="post-toc-number">3.6.</span> <span class="post-toc-text">递归场景</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#weakMap"><span class="post-toc-number">3.7.</span> <span class="post-toc-text">weakMap</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#参考"><span class="post-toc-number">4.</span> <span class="post-toc-text">参考</span></a></li></ol>
        </nav>
    </aside>


<article id="post-js-数组与递归思想/js-数组与递归思想" class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">js-数组与递归思想</h1>
        <div class="post-meta">
            <time class="post-time" title="2019-11-17 10:37:57" datetime="2019-11-17T02:37:57.000Z" itemprop="datePublished">2019-11-17</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/">js</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/Array/">Array</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/Array/learning/">learning</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/Array/learning/note/">note</a><ul class="article-category-list-child"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/js/Array/learning/note/递归/">递归</a></li></ul></li></ul></li></ul></li></ul></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style="display:none">
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h4 id="数组遍历"><a href="#数组遍历" class="headerlink" title="数组遍历"></a>数组遍历</h4><h5 id="1-for"><a href="#1-for" class="headerlink" title="1. for"></a>1. for</h5><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="number">1</span>, <span class="number">9</span>, <span class="number">99</span>, <span class="number">888</span>, <span class="number">9999</span>]</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; arr.length; i++) &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(i)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="2-for-of"><a href="#2-for-of" class="headerlink" title="2. for of"></a>2. for of</h5><p><strong><code>Iterator</code> 统一的遍历方法</strong>（<a href="http://es6.ruanyifeng.com/#docs/iterator" target="_blank" rel="noopener">详见</a>），可使用 <code>break</code>、<code>continue</code> 和 <code>return</code> 语句</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">let</span> v <span class="keyword">of</span> arr) &#123;</span><br><span class="line">	<span class="built_in">console</span>.log(v)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="3-forEach"><a href="#3-forEach" class="headerlink" title="3. forEach"></a>3. forEach</h5><p>没有返回值，不能 <code>return</code>，可在内部使用 <code>try-catch</code> 块强行终止遍历，但是谁会这么做呢</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// item: 数组元素  index: 数组下标  array: 原数组</span></span><br><span class="line">arr.forEach(<span class="function">(<span class="params">item, index, array</span>)=&gt;</span>&#123;</span><br><span class="line">	<span class="built_in">console</span>.log(item, index, array)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h5 id="4-map"><a href="#4-map" class="headerlink" title="4. map"></a>4. map</h5><p>返回新数组，函数会作用在每一个数组元素上然后返回到一个新的数组中</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// value: 当前遍历的数组元素  index: 当前遍历的数组下标  array: 原数组</span></span><br><span class="line"><span class="keyword">const</span> newArr = arr.map(<span class="function">(<span class="params">value, index, array</span>) =&gt;</span> &#123;</span><br><span class="line">	<span class="keyword">return</span> value + <span class="number">1</span></span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">// newArr =&gt; [2, 10, 100, 889, 10000]</span></span><br></pre></td></tr></table></figure>
<h5 id="5-reduce"><a href="#5-reduce" class="headerlink" title="5. reduce"></a>5. reduce</h5><p><strong>累加器</strong>，返回一个累加后的数值，将数组遍历累加，将数组每一项与前一项做累加，结果进入下一次累加</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// prevVal: 前一轮累加值  currentVal: 当前数组元素  startVal: 初始值（可不传，以数组第一项作为初始值）</span></span><br><span class="line"><span class="keyword">var</span> result = arr.reduce(<span class="function">(<span class="params">prevVal, currentVal</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> prevVal + currentVal</span><br><span class="line">&#125;, startVal)</span><br></pre></td></tr></table></figure>
<p> 注： <strong>reduceRight</strong> 从右往左遍历累加</p>
<h5 id="6-filter"><a href="#6-filter" class="headerlink" title="6. filter"></a>6. filter</h5><p>遍历<strong>过滤</strong>，返回 <code>true</code> 则存进新数组中，<code>false</code> 则丢弃</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 大于 99 的将会被放到新数组 newArr 中</span></span><br><span class="line"><span class="keyword">const</span> newArr = arr.filter(<span class="function"><span class="params">v</span> =&gt;</span> &#123;</span><br><span class="line">	<span class="keyword">if</span> (v &gt; <span class="number">99</span>) &#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="literal">false</span></span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">// 或</span></span><br><span class="line"><span class="keyword">const</span> newArr = arr.filter(<span class="function"><span class="params">v</span> =&gt;</span> v &gt; <span class="number">99</span>)</span><br></pre></td></tr></table></figure>
<h5 id="7-some"><a href="#7-some" class="headerlink" title="7. some"></a>7. some</h5><p>返回<strong>布尔值</strong>，只要<strong>其中一项满足条件</strong>则返回 <code>true</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 元素其中一项大于99即返回true</span></span><br><span class="line"><span class="keyword">const</span> b = arr.some(<span class="function">(<span class="params">item, index. array</span>) =&gt;</span> item &gt; <span class="number">99</span>)</span><br></pre></td></tr></table></figure>
<h5 id="8-every"><a href="#8-every" class="headerlink" title="8. every"></a>8. every</h5><p>返回<strong>布尔值</strong>，只有<strong>所有元素满足条件</strong>才返回 <code>true</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 数组元素都大于0才返回true</span></span><br><span class="line"><span class="keyword">const</span> b = arr.every(<span class="function">(<span class="params">item, index. array</span>) =&gt;</span> item &gt; <span class="number">0</span>)</span><br></pre></td></tr></table></figure>
<h5 id="9-find"><a href="#9-find" class="headerlink" title="9. find"></a>9. find</h5><p>返回<strong>数组元素</strong>，查找符合条件的第一个元素，并将其返回，否则返回 <code>undefined</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [&#123; <span class="attr">name</span>: <span class="string">'Andy'</span>, <span class="attr">age</span>: <span class="number">18</span> &#125;, &#123; <span class="attr">name</span>: <span class="string">'Bob'</span>, <span class="attr">age</span>: <span class="number">22</span> &#125;]</span><br><span class="line"><span class="keyword">const</span> ele = arr.find(<span class="function"><span class="params">v</span> =&gt;</span> v.name === <span class="string">'Andy'</span>)</span><br><span class="line"><span class="comment">// ele: &#123; name: 'Andy', age: 18 &#125;</span></span><br></pre></td></tr></table></figure>
<h5 id="10-findIndex"><a href="#10-findIndex" class="headerlink" title="10. findIndex"></a>10. findIndex</h5><p>返回元素<strong>索引</strong>，查找符合条件的第一个元素，并将其<strong>索引</strong>返回，否则返回 <code>-1</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [&#123; <span class="attr">name</span>: <span class="string">'Andy'</span>, <span class="attr">age</span>: <span class="number">18</span> &#125;, &#123; <span class="attr">name</span>: <span class="string">'Bob'</span>, <span class="attr">age</span>: <span class="number">22</span> &#125;]</span><br><span class="line"><span class="keyword">const</span> ele = arr.findIndex(<span class="function"><span class="params">v</span> =&gt;</span> v.name === <span class="string">'Andy'</span>)</span><br><span class="line"><span class="comment">// ele: 0</span></span><br></pre></td></tr></table></figure>
<h5 id="11-keys，values，entries"><a href="#11-keys，values，entries" class="headerlink" title="11.  keys，values，entries"></a>11.  <strong>keys，values，entries</strong></h5><p>常用于遍历对象，但也可遍历数组，省略…</p>
<h4 id="this指向的场景"><a href="#this指向的场景" class="headerlink" title="this指向的场景"></a>this指向的场景</h4><p><strong>自执行函数</strong>中的<code>this</code>，实际上是指向<code>window</code></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> bar = &#123;</span><br><span class="line">	foo:<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;<span class="keyword">return</span> <span class="keyword">this</span>.baz&#125;,</span><br><span class="line">	baz: <span class="number">1</span></span><br><span class="line">&#125;;</span><br><span class="line">(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>);</span><br><span class="line">	<span class="built_in">console</span>.log(<span class="keyword">typeof</span> <span class="built_in">arguments</span>[<span class="number">0</span>]());</span><br><span class="line">&#125;)(bar.foo)</span><br></pre></td></tr></table></figure>
<h4 id="递归"><a href="#递归" class="headerlink" title="递归"></a><a href="https://mp.weixin.qq.com/s/N2pfi2rANMpOX_H6AgyhMg" target="_blank" rel="noopener">递归</a></h4><h5 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h5><p>函数内部调用自己，称为递归。当然需要注意临界条件以退出递归。</p>
<h5 id="关键"><a href="#关键" class="headerlink" title="关键"></a>关键</h5><ul>
<li>写出递归公式</li>
<li>找到终止条件</li>
</ul>
<h5 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h5><ol>
<li><p><strong>排队取票例子</strong>（单分支层层递归）</p>
<p>排队过程中，我想知道我排在队伍的第几个，那我去问前面一个人他是第几位，如果前面那个人知道自己第几位，那我就加一即可，如果我前面的那个人也不知道自己在第几位，那他可以继续往前问，直到队伍第一位<strong>终止</strong>，那么可以尝试写出<strong>递归公式</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">f(n) = f(n<span class="number">-1</span>) + <span class="number">1</span></span><br><span class="line"><span class="comment">// f(n) 是我所在的当前位置</span></span><br><span class="line"><span class="comment">// f(n-1) 是我前面那个人所在的位置</span></span><br><span class="line"><span class="comment">// + 1 是我相对于前面那个人的相对位置</span></span><br><span class="line"><span class="comment">// 我前面那个人如果想知道自己在队伍的哪个位置，也可同样套这个公式，即形成了递归</span></span><br><span class="line">f(<span class="number">1</span>) = <span class="number">1</span> <span class="comment">// 终止条件</span></span><br></pre></td></tr></table></figure>
<p><strong>递归代码</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">f</span>(<span class="params">n</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(n === <span class="number">1</span>) <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">return</span> f(n<span class="number">-1</span>) + <span class="number">1</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<ol start="2">
<li><p><strong>走台阶例子</strong>（多分支并列递归）</p>
<p><strong>题：</strong>假设有 <code>n</code> 个台阶，每次你可以跨一个台阶或者两个台阶，请问走这 <code>n</code> 个台阶有多少种走法？</p>
<p>关键点是先找<strong>递归公式</strong>，第一步的走法，可以分为两种，走一个台阶，或者是走两个台阶。而第二步的走法，也同样是两种。所以 <code>n</code> 个台阶的走法 = （走一个台阶后， <code>n-1</code> 个台阶的走法） + （走两个台阶后， <code>n-2</code> 个台阶的走法）。写出<strong>递归公式</strong>就是</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">f(n) = f(n<span class="number">-1</span>) + f(n<span class="number">-2</span>)</span><br></pre></td></tr></table></figure>
<p>那么<strong>终止条件</strong>是什么？</p>
<p>可以试想，当只剩最后一个台阶的时候，只能走一步，即只有一种走法，可得</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">f(<span class="number">1</span>) = <span class="number">1</span></span><br></pre></td></tr></table></figure>
<p>但是这个终止条件是否已经足够？试想当还剩两个台阶的时候，同样可以一步走两个台阶走完，但是也可以一步一个台阶的分开两步走完，即有两种走法，可得</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">f(<span class="number">2</span>) = <span class="number">2</span></span><br></pre></td></tr></table></figure>
<p>以上两个公式就是此递归的<strong>终止条件</strong>了。</p>
<p>那<strong>递归代码</strong>怎么写呢？</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">walk</span>(<span class="params">n</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(n === <span class="number">1</span>) <span class="keyword">return</span> <span class="number">1</span>; <span class="comment">// 两个终止条件</span></span><br><span class="line">    <span class="keyword">if</span>(n === <span class="number">2</span>) <span class="keyword">return</span> <span class="number">2</span>;</span><br><span class="line">    <span class="keyword">return</span> f(n<span class="number">-1</span>) + f(n<span class="number">-2</span>); <span class="comment">// 递归</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h5 id="递归注意事项"><a href="#递归注意事项" class="headerlink" title="递归注意事项"></a>递归注意事项</h5><ol>
<li><p>爆栈</p>
<p>函数调用会使用<strong>栈</strong>来保存临时变量，每调用一个函数，都会将临时变量压入<strong>内存栈</strong>，等函数执行完了才出栈。如果递归求解的数据规模很大，调用层次很深，一直压入栈，就会有堆栈溢出的风险</p>
<h6 id="优化"><a href="#优化" class="headerlink" title="优化"></a>优化</h6><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 使用全局变量来记录递归的深度</span></span><br><span class="line"><span class="keyword">let</span> depth = <span class="number">0</span>;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">f</span>(<span class="params">n</span>) </span>&#123;</span><br><span class="line">    ++depth;</span><br><span class="line">    <span class="keyword">if</span>(depth &gt; <span class="number">1000</span>) <span class="keyword">throw</span> exception; <span class="comment">// 限制递归深度</span></span><br><span class="line">    <span class="keyword">if</span>(n === <span class="number">1</span>) <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">return</span> f(n<span class="number">-1</span>) + <span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>但是如果递归深度达到了 <code>1000</code> 次，那真是造孽，还是考虑其他办法吧，而且递归过程中如果有更多的变量被压入栈中，更无法保证递归深度限制多少合适，所以一般递归深度也就几次。</p>
</li>
</ol>
<ol start="2">
<li><p>重复计算</p>
<p>如前面的走台阶的例子，比如</p>
<p>计算 <code>f(5)</code> 时</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">f(<span class="number">5</span>) = f(<span class="number">4</span>) + f(<span class="number">3</span>)</span><br></pre></td></tr></table></figure>
<p>在计算 f(4) 时</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">f(<span class="number">4</span>) = f(<span class="number">3</span>) + f(<span class="number">2</span>)</span><br></pre></td></tr></table></figure>
<p>这样，<code>f(3)</code> 就重复计算了两次，继续往下会发现 <code>f(2)</code> 同样计算了两次</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">f(<span class="number">3</span>) = f(<span class="number">2</span>) + f(<span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<p>因此，可以知道，递归函数中存在大量的重复计算，那应该如何避免重复计算问题？可不可以将计算结果先存起来，下次遇到重复计算时，直接从中取出计算结果，作者告诉我们是可以的，先看以下代码</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> mapData = <span class="keyword">new</span> map();</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">walk</span>(<span class="params">n</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(n === <span class="number">1</span>) <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">if</span>(n === <span class="number">2</span>) <span class="keyword">return</span> <span class="number">2</span>;</span><br><span class="line">    <span class="comment">// 值的判断和存储</span></span><br><span class="line">    <span class="keyword">if</span>(mapData.get(n)) &#123;</span><br><span class="line">        <span class="keyword">return</span> mapData.get(n);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">let</span> value =  walk(n<span class="number">-1</span>) + walk(n<span class="number">-2</span>);</span><br><span class="line">    mapData.set(n, value); <span class="comment">// 储存 n 的计算结果</span></span><br><span class="line">    <span class="keyword">return</span> value;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h5 id="感悟"><a href="#感悟" class="headerlink" title="感悟"></a>感悟</h5><ul>
<li><p>关键是找到递归的<strong>递归公式</strong>和<strong>终止条件</strong></p>
</li>
<li><p>不要尝试一层一层分解递归的每个步骤</p>
</li>
</ul>
<h5 id="递归场景"><a href="#递归场景" class="headerlink" title="递归场景"></a>递归场景</h5><ol>
<li><p>数组拍平</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> a = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, [<span class="number">1</span>, <span class="number">2</span>, [<span class="number">1</span>, <span class="number">4</span>], [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]]]</span><br><span class="line"><span class="comment">// 由于无法确定数组的嵌套层级，故使用递归</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">flat</span>(<span class="params">a = [], result = []</span>) </span>&#123;</span><br><span class="line">    a.forEach(<span class="function"><span class="params">item</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">if</span>(<span class="built_in">Object</span>.prototype.toString.call(item) === <span class="string">'[object Array]'</span>) &#123;</span><br><span class="line">            result = result.concat(flat(item, []));</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            result.push(item)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(flat(a)); <span class="comment">// [1, 2, 3, 1, 2, 1, 4, 1, 2, 3]</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>简易深拷贝</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">clone</span>(<span class="params">target, map = new WeakMap(</span>)) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(<span class="keyword">typeof</span> target === <span class="string">'object'</span>) &#123;</span><br><span class="line">    	<span class="keyword">let</span> cloneTarget = <span class="built_in">Array</span>.isArray(target) ? [] : &#123;&#125;</span><br><span class="line">        <span class="comment">// 防止循环引用</span></span><br><span class="line">        <span class="keyword">if</span>(map.get(target)) &#123;</span><br><span class="line">            <span class="keyword">return</span> map.get(target)</span><br><span class="line">        &#125;</span><br><span class="line">        map.set(target, cloneTarget)</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">const</span> key <span class="keyword">in</span> target) &#123;</span><br><span class="line">            <span class="comment">// 递归拷贝</span></span><br><span class="line">            cloneTarget[key] = clone(target[key], map)</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 返回拷贝完的值</span></span><br><span class="line">        <span class="keyword">return</span> cloneTarget</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">// 简单数据类型直接返回</span></span><br><span class="line">        <span class="keyword">return</span> target</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h5 id="weakMap"><a href="#weakMap" class="headerlink" title="weakMap"></a>weakMap</h5><p>   <code>weakMap</code>对象虽然也是一组键/值对的集合，其中的键是<strong>弱引用</strong>的，弱引用是指不能确保其引用的对象不会被垃圾回收器回收的引用。一个对象若只被弱引用所引用，则被认为是<strong>不可访问</strong>（或<strong>弱可访问</strong>）的，并因此可能在任何时候被<strong>回收</strong></p>
<h4 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h4><p><a href="https://mp.weixin.qq.com/s/N2pfi2rANMpOX_H6AgyhMg" target="_blank" rel="noopener">聊聊面试必考-递归思想与实战</a></p>

        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2019-11-17T03:05:48.407Z" itemprop="dateUpdated">2019-11-17 11:05:48</time>
</span><br>


        
        关于学习类文章网上已经有非常多，而此处文章都是我在学习过程中整理摘录的笔记，参考文章可以点击文末的参考链接进行查阅
        
    </div>
    
    <footer>
        <a href="https://lafen.gitee.io">
            <img src="/img/avatar.jpg" alt="lafen">
            lafen
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Array/">Array</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/js/">js</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/learning/">learning</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/note/">note</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/递归/">递归</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/&title=《js-数组与递归思想》 — lafen&pic=https://lafen.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/&title=《js-数组与递归思想》 — lafen&source=lafen's personal blog" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《js-数组与递归思想》 — lafen&url=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/&via=https://lafen.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2019/11/17/vue-源码笔记/vue-源码笔记/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">vue-源码笔记</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2019/10/15/mpvue-vue-socketio使用实现即时通讯/mpvue-vue-socketio使用实现即时通讯/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">mpvue-vue-socketio使用实现即时通讯</h4>
      </a>
    </div>
  
</nav>



    




















</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        打笔巨款？~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/wechat.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check" data-wechat="/img/wechat.jpg" data-alipay="/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style="display:none">
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style="display:none">
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>lafen &copy; 2019 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/&title=《js-数组与递归思想》 — lafen&pic=https://lafen.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/&title=《js-数组与递归思想》 — lafen&source=lafen's personal blog" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《js-数组与递归思想》 — lafen&url=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/&via=https://lafen.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lafen.gitee.io/2019/11/17/js-数组与递归思想/js-数组与递归思想/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"positon":"right","width":150,"height":300},"mobile":{"show":true,"scale":0.8},"react":{"opacity":0.8,"opacityDefault":0.8,"opacityOnHover":0.6},"log":false});</script></body>
</html>
